var express = require('express')
var router = express.Router()

router.use(function (req , res , next) {
    console.log('Time :' , Date.now());
    next();
})

router.use('/user/:id' , function (req , res , next) {
    console.log('Requet : ' , req.originalUrl);
    next()
},function (req , res , next) {
    console.log('Request Type :', req.method);
    next();
})

router.get('/user/:id' ,function (req ,res , next) {
    console.log('ID : ' , req.params.id);
    if (req.params.id === 1) next('next')


    else next()
}, function (req , res , next) {
    console.log("USER");
    res.send('User Info')
    res.render('regular')
})

router.get('/user/:id' ,function (req , res , next) {
    res.end(req.params.id)
})

// 静态文件
var options = {
  dotfiles: 'ignore',
  etag: false,
  extensions: ['htm', 'html'],
  index: false,
  maxAge: '1d',
  redirect: false,
  setHeaders: function (res, path, stat) {
    res.set('x-timestamp', Date.now())
  }
}

router.use(express.static('public', options))

module.exports = router;
